package com.monas.client.jfree;

import java.io.File;
import java.io.IOException;

import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.data.general.AbstractDataset;

public abstract class AbstractMonasChart {

	protected JFreeChart chart = null;

	protected AbstractDataset dataSet = null;

	protected String title;

	protected String xLabel;

	protected String yLabel;

	public abstract void createChart();

	public abstract void clearData();

	protected abstract int getWidth();

	protected abstract int getHeight();

	public AbstractMonasChart(String title, String xLabel, String yLabel) {
		this.title = title;
		this.xLabel = xLabel;
		this.yLabel = yLabel;
	}

	public JFreeChart getChart() {
		return chart;
	}

	public void saveChartIntoPNG(String pathFile) {
		try {
			ChartUtilities.saveChartAsPNG(new File(pathFile), chart,
					getWidth(), getHeight());
		} catch (IOException e) {
			throw new RuntimeException("Fail create file from chart because "
					+ e.getMessage());
		}
	}

	public void saveChartIntoJPEG(String pathFile) {
		try {
			ChartUtilities.saveChartAsJPEG(new File(pathFile), chart,
					getWidth(), getHeight());
		} catch (IOException e) {
			throw new RuntimeException("Fail create file from chart because "
					+ e.getMessage());
		}
	}

}
